package com.example.demo.domain.conf;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.example.demo.biz.PriceLadderBiz;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author zhiwen huang
 * @date 2020/12/24 22:12
 */
public class LadderValueListener extends AnalysisEventListener<Map<String, String>> {

    Map<Integer, String> headMap;
    List<Map<String, String>> dataMapList = new ArrayList<>();

    private PriceLadderBiz priceLadderBiz;

    public LadderValueListener(PriceLadderBiz biz) {
        priceLadderBiz = biz;
    }

    @Override
    public void invoke(Map<String, String> map, AnalysisContext analysisContext) {

        dataMapList.add(map);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        priceLadderBiz.export(headMap, dataMapList);
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> map, AnalysisContext context) {
        headMap = map;
    }
}
